from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)


#数据库的变量
HOST = '127.0.0.1'
PORT = 3306
DATABASE = 'itbz'
USER = 'root'
PWD = 'root'
DB_URI = f'mysql+pymysql://{USER}:{PWD}@{HOST}:{PORT}/{DATABASE}'

app.config['SQLALCHEMY_DATABASE_URI'] = DB_URI

#链接数据库
db = SQLAlchemy(app)

#创建模型类
class User(db.Model):
    __tablename__ = 't_user'
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    name = db.Column(db.String(32))

    def __repr__(self):
        return f'<user id={self.id} name={self.name}'

#使用migrate同步表结构
from flask_migrate import Migrate
Migrate(app,db)